import { Hono } from "hono";
import { zValidator } from "@hono/zod-validator";
import { z } from "zod";
import { court } from "@/db/schema";
import { asc, desc, eq } from "drizzle-orm";
import { db } from "@/db/drizzle";

const app = new Hono()
  .get("/", (c) => {
    return c.json({ user: "GET" });
  })
  .get(
    "/:name",
    zValidator(
      "param",
      z.object({
        name: z.string(),
      })
    ),
    async (c) => {
      const { name } = c.req.valid("param");

      const data = await db
        .select()
        .from(court)
        .where(eq(court.name, name))
        .orderBy(
          asc(court.createdAt),
          desc(court.updatedAt),
        );

      return c.json({ data });
    },
  );

export default app;
